package com.scwatch.common.util;


import cn.jiguang.common.utils.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Created by Ly on 2017/7/5.
 * 请求 参数获取
 */
public class RequestUtils {

    public  static Map<String,String> getRequest(HttpServletRequest request) {

        Map valueMap = new HashMap();
        try {
            Map<String, String[]> map = request.getParameterMap();
            Set keSet = map.entrySet();
            for (Iterator itr = keSet.iterator(); itr.hasNext(); ) {
                Map.Entry me = (Map.Entry) itr.next();
                Object ok = me.getKey();
                Object ov = me.getValue();
                String[] value = new String[1];
                if (ov instanceof String[]) {
                    value = (String[]) ov;
                } else {
                    value[0] = ov.toString();
                }
                for (int k = 0; k < value.length; k++) {
                    String val = value[k].trim();
                    if (StringUtils.isNotEmpty(val))
                        valueMap.put(ok,val );
                }
            }
        }catch (Exception e){
            e.getStackTrace();
        }finally {
            return valueMap;
        }
    }
}
